package org.red_cross_service.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.red_cross_service.common.anno.NoNeedToken;
import org.red_cross_service.common.response.Response;
import org.red_cross_service.domain.dto.UserProcess;
import org.red_cross_service.domain.entity.LearnRecordEntity;
import org.red_cross_service.service.ServiceComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/record")
@CrossOrigin
public class LearnRecordController {

    @Autowired
    ServiceComponent serviceComponent;

    //更新视频进度
    @NoNeedToken
    @PostMapping("/uploadProcess")
    public Response updateUserVideoProcess(@RequestBody UserProcess process) throws JsonProcessingException {
        return serviceComponent.getLearnRecordService().updateUserVideoProcess(process);
    }

    @NoNeedToken
    @PostMapping("/update")
    public Response update(@RequestBody LearnRecordEntity learnRecord) {
        return serviceComponent.getLearnRecordService().update(learnRecord);
    }

    @NoNeedToken
    @PostMapping("/list")
    public Response getLearnRecordList(@RequestBody LearnRecordEntity learnRecord) {
        return serviceComponent.getLearnRecordService().getLearnRecordList(learnRecord);
    }

    /**
     * @param userId 用户id
     * @param type   true 进行中  false 已结束
     */
    @NoNeedToken
    @GetMapping("/queryLearnRecordByUserId")
    public Response getLearnRecordByUserId(Integer userId, Boolean type) {
        return serviceComponent.getLearnRecordService().queryLearnRecordByUserId(userId, type);
    }

    @NoNeedToken
    @PostMapping("/selectOne")
    public Response selectOne(@RequestBody LearnRecordEntity learnRecord) {
        return Response.success(serviceComponent.getLearnRecordService().selectOne(learnRecord));
    }

}
